/*-+-*****************************************************************************
 Copyright (C) 2009-2012 Oceanside Software Corporation (R)
 Dallas, Texas

 Author       : Jason T. Brower
 Purpose      : This file is part of a point-of-sale software package
                originally written for Table-Service Restaurants.
              
 Date         : July 8th of 2012
              
 History      : The application that this software file belongs to was 
                written over a 3-Year period.  The first version was written
                in C# .Net 3.5 using Windows Forms.  Being new to .Net at
                the time, I soon learned of Windows Presentation Foundation,
                liked the graphics capabilities and databinding so I
                migrated to WPF.  When the .Net 4.0 framework was released
                the application was migrated from 3.5 to 4.0. Now today,
                .Net 4.5 RC is out and I was already in process of migrating
                before I made this public.
                
Excuse Me     : Please excuse the coding style, it is not representative of
                my typical work.  During the three years I was under a very
                tight budget, constantly running out of funding and was 
                working 18 hour days hyped up on 5-Hour Energy.  The 
                design is not textbook.  It is monolythic because of
                previous issues I will not get into.  There are few comments
                in the code and the ones that are there may be incorrect.
                
What it is not: This is not the exact version that I took through PA-DSS 2.0
                nor is it the exact version running at my customer sites.
                I removed some details for security purposes including some
                encryption algorithms.  The reporting was removed because
                I was including a third party library that cannot be 
                published with this Open Source.
                
What it is    : This application has been running at high volume restaraunts
                for over a year.  It never freezes, crashes or does anything
                unexpected.  So long as it is built, installed and configured
                correctly, it is a strong system that we can all enhance.

Contact       : Please note that I can no longer work for free.  However, you
                can reach me at information@oceansidesw.com.                                                      

*********************************************************************************/
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace Oceanside
{
    /// <summary>
    /// Interaction logic for ShineButton_52_58.xaml
    /// </summary>
    public partial class ShineButton_52_58 : UserControl
    {	
        public ShineButton_52_58()
        {
            this.InitializeComponent();
            this.MouseUp += new MouseButtonEventHandler(FlatButton_MouseUp_NOTHROW);
            this.MouseDown += new MouseButtonEventHandler(FlatButton_52_58_MouseDown_NOTHROW);
            this.MouseLeave += new MouseEventHandler(FlatButton_MouseLeave_NOTHROW);			
        }

        static ShineButton_52_58()
        {
            FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata(new PropertyChangedCallback(OnButtonBgChanged));
            ButtonBackgroundProperty = DependencyProperty.Register(
                "ButtonBackground", 
                typeof(Brush),
                typeof(ShineButton_52_58),
                metadata
            );
            
            ButtonBackgroundMouseDownProperty = DependencyProperty.Register(
                "ButtonBackgroundMouseDown",
                typeof(Brush),
                typeof(ShineButton_52_58) ///Note the lack of metadata thats not needed for this one
            );

            metadata = new FrameworkPropertyMetadata(new PropertyChangedCallback(OnButtonButtonBBChanged));
            ButtonBorderBrushProperty = DependencyProperty.Register(
                "ButtonBorderBrush",
                typeof(Brush),
                typeof(ShineButton_52_58),
                metadata
            );	
            
            metadata = new FrameworkPropertyMetadata(new PropertyChangedCallback(OnButtonContentChanged));
            ButtonContentProperty = DependencyProperty.Register(
                "ButtonContent",
                typeof(UIElement),
                typeof(ShineButton_52_58),
                metadata
            ); 	
            
            ///Routed event
            FlatButtonClickedEvent = EventManager.RegisterRoutedEvent("FlatButtonClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler),
                typeof(ShineButton_52_58));      			
        }
        
        
        /// <summary>
        /// DP Property Callbacks
        /// </summary>
        public static void OnButtonBgChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            ShineButton_52_58 sb = sender as ShineButton_52_58;
            sb.layoutRootBorder.Background = (Brush)args.NewValue;
        }
        public static void OnButtonButtonBBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            ShineButton_52_58 sb = sender as ShineButton_52_58;
            sb.layoutRootBorder.BorderBrush = (Brush)args.NewValue;
        }
        public static void OnButtonContentChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            ShineButton_52_58 sb = sender as ShineButton_52_58;
            sb.contentCanvas.Children.Clear();
            sb.contentCanvas.Children.Add((UIElement)args.NewValue);
        }

        /// <summary>
        /// DP Properties
        /// </summary>
        public static readonly DependencyProperty ButtonBackgroundProperty;
        public Brush ButtonBackground
        {
            get{ return (Brush)GetValue(ButtonBackgroundProperty); }
            set { SetValue(ButtonBackgroundProperty, value); }
        }

        public static readonly DependencyProperty ButtonBackgroundMouseDownProperty;
        public Brush ButtonBackgroundMouseDown
        {
            get { return (Brush)GetValue(ButtonBackgroundMouseDownProperty); }
            set { SetValue(ButtonBackgroundMouseDownProperty, value); }
        }

        public static readonly DependencyProperty ButtonBorderBrushProperty;
        public Brush ButtonBorderBrush
        {
            get { return (Brush)GetValue(ButtonBorderBrushProperty); }
            set { SetValue(ButtonBorderBrushProperty, value); }
        }

        public static readonly DependencyProperty ButtonContentProperty;
        public UIElement ButtonContent
        {
            get { return (UIElement)GetValue(ButtonContentProperty); }
            set { SetValue(ButtonContentProperty, value); }
        }
        
        /// <summary>
        /// The routed event stuff
        /// </summary>
        public static RoutedEvent FlatButtonClickedEvent;
        public event RoutedEventHandler OnFlatButtonClicked
        {
            add { AddHandler(FlatButtonClickedEvent, value); }
            remove { RemoveHandler(FlatButtonClickedEvent, value); }
        }
        protected virtual void OnFlatButtonClickedFunc()
        {
            RoutedEventArgs args = new RoutedEventArgs();
            args.RoutedEvent = FlatButtonClickedEvent;
            RaiseEvent(args);
        }

        /// <summary>
        /// Click Events
        /// </summary>
        void FlatButton_MouseUp_NOTHROW(object sender, MouseButtonEventArgs e)
        {
            try
            {
                e.Handled = true;
                layoutRootBorder.Background = ButtonBackground;
            }
            catch (System.Exception exc)
            {
                Constants.ErrorDispatcher.Notify(Error.EType.E_BUTTON_52_58_UP, exc);
            }
        }
        void FlatButton_52_58_MouseDown_NOTHROW(object sender, MouseButtonEventArgs e)
        {
            try
            {
                OnFlatButtonClickedFunc();
                layoutRootBorder.Background = ButtonBackgroundMouseDown;
            }
            catch (System.Exception exc)
            {
                Constants.ErrorDispatcher.Notify(Error.EType.E_BUTTON_52_58_DWN, exc);
            }
        }

        void FlatButton_MouseLeave_NOTHROW(object sender, MouseEventArgs e)
        {
            try
            {

                e.Handled = true;
                layoutRootBorder.Background = ButtonBackground;
            }
            catch (System.Exception exc)
            {
                Constants.ErrorDispatcher.Notify(Error.EType.E_BUTTON_52_58_LEAVE, exc);
            }
        }		
    }
}
